package schoolsource.command;

import java.io.IOException;
import java.util.Enumeration;
import java.util.logging.Level;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import schoolsource.gui.FormFields;
import schoolsource.gui.FormParser;
import schoolsource.model.ClassContainer;
import schoolsource.model.CourseContainer;
import schoolsource.model.GradeContainer;
import schoolsource.model.HomeworkContainer;
import schoolsource.model.Item;
import schoolsource.model.PairedUserContainer;
import schoolsource.model.PasswordItem;
import schoolsource.model.StringItem;
import schoolsource.model.TermContainer;
import schoolsource.model.UserContainer;
import schoolsource.security.SecurityAuthorizer;
import schoolsource.security.SecurityToken;
import schoolsource.sql.SchoolDBSQL;
import schoolsource.util.SchoolLogger;

/**
 * 
 * @author Steven Steele Copyright 2003
 * 
 * Manages all user/course/class editing processes.
 */
public class EditorCMD extends HttpServlet {

	static {
		System.out.println("TRYING TO LOAD!!!!!!!!!!!");
	}
	/**
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	public void doPost(HttpServletRequest input, HttpServletResponse response)
			throws ServletException, IOException {

		SchoolLogger.logger
				.log(Level.INFO,
						"//////////////////////////////////////////////////////////////");

		SecurityToken infoToken = null; // Declare the session container

		Enumeration e = input.getParameterNames();
		String s;
		SchoolLogger.logger.log(Level.INFO, "List parameter values");
		while (e.hasMoreElements()) {
			s = (String) e.nextElement();
			SchoolLogger.logger.log(Level.INFO, s + ":  "
					+ input.getParameter(s));
		}

		// Set up request dispatcher to display the next page.
		ServletContext sc = getServletContext();
		RequestDispatcher disp;

		// TODO clean up any leftover flags

		String param = input.getParameter(FormFields.PARAMETER);
		String userType = (String) input.getParameter(FormFields.USRTYPE);
		String schoolName = (String) input.getParameter(FormFields.SCHOOLNAME);
		input.setAttribute(FormFields.SCHOOLNAME, schoolName);
		input.setAttribute(FormFields.USRTYPE, userType);
		int gotoPage = -1;
		if (param != null && !"".equals(param)) {
			gotoPage = new Integer(param).intValue();
			SchoolLogger.logger.log(Level.INFO, "Got gotoPage from param: "
					+ gotoPage);
		}

		String temp = input.getParameter(FormFields.EDITORPAGE);
		int editorPage = -1;
		if (temp != null) {
			editorPage = new Integer(temp).intValue();
		}
		// else {
		// editorPage = FormFields.EDSTUDENTPAGE;
		// }

		String linkClicked = (String) input
				.getParameter(FormFields.LINKCLICKED);

		// Get identifying info from the incoming data
		String token;
		String userid;

		// Validate token or user name/password. If not valid, send back the
		// login page with
		// the appropriate message
		if ((token = input.getParameter(FormFields.TOKEN)) != null) {
			SchoolLogger.logger.log(Level.INFO, "found a token");
			infoToken = SecurityAuthorizer.validateToken(token, 'A');

		} else if ((userid = input.getParameter(SchoolDBSQL.USRSCHOOLID)) != null
				&& input.getParameter(SchoolDBSQL.USRPASSWORD) != null
				&& SecurityAuthorizer.isValidAdminLogin(input
						.getParameter(SchoolDBSQL.USRSCHOOLID), input
						.getParameter(SchoolDBSQL.USRPASSWORD), schoolName)) {
			SchoolLogger.logger.log(Level.INFO, "Got a valid login");
			infoToken = SecurityAuthorizer.generateToken();
			infoToken.putValue(FormFields.USRTYPE, new Character('A'));

			infoToken.putValue(FormFields.SCHOOLNAME, schoolName);

			// put the Token in the request so the jsp can retrieve it
			input.setAttribute(FormFields.SESSION, infoToken);

			infoToken.putValue(FormFields.TOKEN, infoToken.toString());

			UserContainer uc = UserContainer.getUserContainer(SchoolDBSQL
					.getSchoolDBSQL(
							infoToken.getValue(FormFields.SCHOOLNAME)
									.toString()).getAssignedID(userid,
							SchoolDBSQL.ADMIN), infoToken.getValue(
					FormFields.SCHOOLNAME).toString());

			uc.getFailures().setValue("0");

			SchoolDBSQL.getSchoolDBSQL(
					infoToken.getValue(FormFields.SCHOOLNAME).toString()).save(
					uc);

			SchoolLogger.logger.log(Level.INFO, "loading user container");

			infoToken.putValue("adminContainer", uc);

		}

		input.setAttribute(FormFields.SESSION, infoToken);

		if (FormFields.LOGOUT.equals(linkClicked)) {
			SchoolLogger.logger.log(Level.INFO, "Logged out");

			// De-allocate the session to free up memory
			if (infoToken != null) {
				SecurityAuthorizer.removeToken(infoToken.toString());
			}
			input.setAttribute("displayMessage", "User logged out.");
			// input.setAttribute(FormFields.SCHOOLNAME, schoolName);
			disp = sc.getRequestDispatcher("/jsp/EditorLogin.jsp");
		} else if (infoToken == null) {
			if (token != null) {
				input.setAttribute("displayMessage",
						"Your login has expired. Please log in again");
			} else if (input.getParameter(SchoolDBSQL.USRSCHOOLID) != null
					|| input.getParameter(SchoolDBSQL.USRPASSWORD) != null) {
				input
						.setAttribute("displayMessage",
								"The username/password you entered could not be validated.");
			}

			// input.setAttribute(FormFields.SCHOOLNAME, schoolName);
			disp = sc.getRequestDispatcher("/jsp/EditorLogin.jsp");

		} else { // then it's a valid login

			infoToken.putValue(FormFields.SUBLINK, input
					.getParameter(FormFields.SUBLINK));

			// If the current main frame should stay
			if (FormFields.PROGRESSLINK.equals(linkClicked)) {
				String classID = (String) input
						.getParameter(FormFields.CLASSNUM);
				infoToken.removeValue(FormFields.CLASSNUM);

				// IntegerItem classAssignedID = new
				// IntegerItem(SchoolDBSQL.CLASSASSIGNEDID, (String)
				// infoToken.removeValue(FormFields.CLASSNUM), false);
				ClassContainer classC = ClassContainer.getClassContainer(
						classID, schoolName);
				String teacherID = SchoolDBSQL.getSchoolDBSQL(schoolName)
						.getClassTeacherID(classC.getClassAssignedID())
						.toString();
				String studentID = (String) input
						.getParameter(FormFields.STUDENTID);

				PairedUserContainer studentContainer = PairedUserContainer
						.getPairedContainer(studentID, schoolName);
				UserContainer teacherContainer = UserContainer
						.getUserContainer(teacherID, schoolName);
				HomeworkContainer homeworkContainer[] = SchoolDBSQL
						.getSchoolDBSQL(schoolName).loadStudentClassHomework(
								classC.getClassAssignedID());

				infoToken.putValue(FormFields.CLASSNUM, classC
						.getClassAssignedID());
				infoToken.putValue("studentProgress", studentContainer);
				infoToken.putValue("teacherContainer", teacherContainer);
				infoToken.putValue("homeworkContainer", homeworkContainer);

				// load grades
				GradeContainer gradeContainer[] = new GradeContainer[homeworkContainer.length];

				for (int j = 0; j < homeworkContainer.length; j++) {
					gradeContainer[j] = GradeContainer.getGradeContainer(
							homeworkContainer[j].getClassID().toString(),
							homeworkContainer[j].getHomeworkID().toString(),
							studentID, schoolName);
				}
				infoToken.putValue("studentGrade", gradeContainer);

				disp = sc.getRequestDispatcher("/jsp/ProgressReportEditor.jsp");
			}
			// If both frames should be repopulated
			else if (FormFields.SUBFRAME.equals((String) input
					.getParameter(FormFields.CURRENT))) {
				// If the user is trying to view something, figure out the type
				// (student, class, etc)
				// and assignedID and send back the appropriate information.
				if (FormFields.VIEWACTION.equals(linkClicked)) {

					String id;
					SchoolLogger.logger.log(Level.INFO,
							"Viewaction -- editorPage: " + editorPage);

					infoToken.putValue(FormFields.EDITORPAGE, "" + editorPage);
					Item assignedClassList[][];
					Item assignedTeacherList[][];

					switch (editorPage) {
					case FormFields.EDSTUDENTPAGE: // view student
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadViewStudentInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc
								.getRequestDispatcher("/jsp/StudentEditor.jsp");
						break;
					case FormFields.EDTEACHERPAGE: // view teacher
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadViewTeacherInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc
								.getRequestDispatcher("/jsp/TeacherEditor.jsp");
						break;
					case FormFields.EDCOURSEPAGE: // view course
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadViewCourseInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc.getRequestDispatcher("/jsp/CourseEditor.jsp");
						break;
					case FormFields.EDCLASSPAGE: // view class
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadViewClassInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc.getRequestDispatcher("/jsp/ClassEditor.jsp");
						break;
					case FormFields.EDTERMPAGE: // view term
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadViewTermInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc.getRequestDispatcher("/jsp/TermEditor.jsp");
						break;
					default: // edit parent
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadViewParentInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc.getRequestDispatcher("/jsp/ParentEditor.jsp");
						break;
					}
				}
				// If the user is trying to create something new, figure out
				// what type (student, class, etc)
				// and load any necessary information for the page
				else if (FormFields.NEWACTION.equals(linkClicked)) {

					SchoolLogger.logger.log(Level.INFO,
							"Newaction -- editorPage: " + editorPage);

					infoToken.putValue(FormFields.EDITORPAGE, "" + editorPage);

					switch (editorPage) {
					case FormFields.EDSTUDENTPAGE: // add student
						loadNewStudentInfo(infoToken, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc
								.getRequestDispatcher("/jsp/StudentEditor.jsp");
						break;
					case FormFields.EDTEACHERPAGE: // add teacher
						loadNewTeacherInfo(infoToken, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc
								.getRequestDispatcher("/jsp/TeacherEditor.jsp");
						break;
					case FormFields.EDCOURSEPAGE: // add course
						infoToken.putValue(FormFields.EDITSTATUS,
								FormFields.NEW);
						// TODO Validate that this is correct - should a new one
						// be created, or should one be loaded?
						infoToken.putValue("courseContainer", CourseContainer
								.getCourseContainer("-1", infoToken.getValue(
										FormFields.SCHOOLNAME).toString()));
						disp = sc.getRequestDispatcher("/jsp/CourseEditor.jsp");
						break;
					case FormFields.EDCLASSPAGE: // add class
					// TODO Validate that this is correct - should a new one be
					// created, or should one be loaded?
						infoToken.putValue("classContainer", ClassContainer
								.getClassContainer("-1", infoToken.getValue(
										FormFields.SCHOOLNAME).toString()));
						loadNewCourseInfo(infoToken);
						disp = sc.getRequestDispatcher("/jsp/ClassEditor.jsp");
						break;
					case FormFields.EDTERMPAGE: // add term
						infoToken.putValue(FormFields.EDITSTATUS,
								FormFields.NEW);
						infoToken.putValue("termContainer", TermContainer
								.getTermContainer("", infoToken.getValue(
										FormFields.SCHOOLNAME).toString()));
						disp = sc.getRequestDispatcher("/jsp/TermEditor.jsp");
						break;
					default: // add parent
						loadNewParentInfo(infoToken, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc.getRequestDispatcher("/jsp/ParentEditor.jsp");
						break;
					}
				}
				// If the user is trying to edit something, figure the type, get
				// the assigned ID,
				// and load the appropriate information
				else if (FormFields.EDITACTION.equals(linkClicked)) {
					String id;

					SchoolLogger.logger.log(Level.INFO,
							"Editaction -- editorPage: " + editorPage);

					infoToken.putValue(FormFields.EDITORPAGE, "" + editorPage);

					switch (editorPage) {
					case FormFields.EDSTUDENTPAGE: // edit student
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadEditStudentInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc
								.getRequestDispatcher("/jsp/StudentEditor.jsp");
						break;
					case FormFields.EDTEACHERPAGE: // edit teacher
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadEditTeacherInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc
								.getRequestDispatcher("/jsp/TeacherEditor.jsp");
						break;
					case FormFields.EDCOURSEPAGE: // edit course
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadEditCourseInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc.getRequestDispatcher("/jsp/CourseEditor.jsp");
						break;
					case FormFields.EDCLASSPAGE: // edit class
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadEditClassInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc.getRequestDispatcher("/jsp/ClassEditor.jsp");
						break;
					case FormFields.EDTERMPAGE: // edit term
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadEditTermInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc.getRequestDispatcher("/jsp/TermEditor.jsp");
						break;
					default: // edit parent
						id = (String) input.getParameter(FormFields.PARAMETER);
						loadEditParentInfo(infoToken, id, infoToken.getValue(
								FormFields.SCHOOLNAME).toString());
						disp = sc.getRequestDispatcher("/jsp/ParentEditor.jsp");
						break;
					}
				}
				// If the user is trying to save something, figure out the type,
				// parse the changes,
				// and save the changes if appropriate.
				else if (FormFields.SAVEACTION.equals(linkClicked)) {

					SchoolLogger.logger.log(Level.INFO, "Save -- editorPage: "
							+ editorPage);

					infoToken.putValue(FormFields.EDITORPAGE, "" + editorPage);

					switch (editorPage) {
					case FormFields.EDSTUDENTPAGE: // save student
					// TODO The following needs to getCourseContainer(id,
					// dbName);
						UserContainer studcont = PairedUserContainer
								.getPairedContainer(
										input
												.getParameter(SchoolDBSQL.USRASSIGNEDID),
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString());
						// Parse the information from the form and populate the
						// container
						String message = "";
						try {
							FormParser.updateStudent(input, studcont,
									(String) infoToken
											.getValue(FormFields.SCHOOLNAME));
						} catch (IOException ioe) {
							// could not save attached picture
							message = "Could not save attached picture. ";
						}
						saveStudentInfo(input, studcont, infoToken);
						if (studcont.getAssignedID().toString().equals("-1")
								|| SchoolDBSQL.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString()).isUniqueUserID(
										studcont.getSchoolID(),
										studcont.getType())) {
							saveStudentInfo(input, studcont, infoToken);
							if ("" != message) {
								message += "Other changes saved.";
							} else {
								message = "Changes saved.";
							}
							infoToken.putValue("displayMessage", message);
							loadEditorMainParameters(infoToken, editorPage);
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						} else {
							// TODO load the student editor instead of eview
							infoToken.putValue(FormFields.SUBLINK, studcont
									.getAssignedID().toString());
							// infoToken.putValue(FormFields.EDITORPAGE,
							// Integer.toString(FormFields.EDSTUDENTPAGE));
							studcont.getSchoolID().setValue("<enter new id>");
							loadEditStudentInfo(infoToken, studcont
									.getAssignedID().toString(), infoToken
									.getValue(FormFields.SCHOOLNAME).toString());
							infoToken
									.putValue(
											"displayMessage",
											message
													+ "Student ID already exists. Please choose a new ID.");
							loadEditorMainParameters(infoToken,
									FormFields.EDSTUDENTPAGE);

							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						}
						infoToken.putValue("studentContainer", studcont);
						break;
					case FormFields.EDTEACHERPAGE: // save teacher
					// TODO The following needs to getUserContainer(id, dbName);
						UserContainer teachercont = UserContainer
								.getUserContainer(
										input
												.getParameter(SchoolDBSQL.USRASSIGNEDID),
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString());
						// Parse the information from the form and populate the
						// container
						FormParser.updateTeacher(input, teachercont);
						saveTeacherInfo(input, teachercont, infoToken);
						if (teachercont.getAssignedID().toString().equals("-1")
								|| SchoolDBSQL.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString()).isUniqueUserID(
										teachercont.getSchoolID(),
										teachercont.getType())) {
							saveTeacherInfo(input, teachercont, infoToken);
							infoToken.putValue("displayMessage",
									"Changes saved");
							loadEditorMainParameters(infoToken, editorPage);
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						} else {
							// TODO load the teacher editor instead of eview
							teachercont.getSchoolID()
									.setValue("<enter new id>");
							loadEditTeacherInfo(infoToken, teachercont
									.getAssignedID().toString(), infoToken
									.getValue(FormFields.SCHOOLNAME).toString());
							infoToken
									.putValue("displayMessage",
											"Teacher ID already exists. Please choose a new ID.");
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						}
						infoToken.putValue("teacherContainer", teachercont);
						break;
					case FormFields.EDCOURSEPAGE: // save course
					// TODO The following needs to getCourseContainer(id,
					// dbName);

						CourseContainer course = CourseContainer
								.getCourseContainer(
										input
												.getParameter(SchoolDBSQL.COURSEASSIGNEDID),
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString());
						// Parse the information from the form and populate the
						// container
						FormParser.updateCourse(input, course);
						saveCourseInfo(course, infoToken);
						if (course.getCourseAssignedID().toString()
								.equals("-1")
								|| SchoolDBSQL.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString()).isUniqueCourseID(
										course.getCourseSchoolID())) {
							infoToken.putValue("displayMessage",
									"Changes saved");
							loadEditorMainParameters(infoToken, editorPage);
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						} else {
							// TODO load the course editor instead of eview
							course.getCourseSchoolID().setValue(
									"<enter new id>");
							loadEditCourseInfo(infoToken, course
									.getCourseAssignedID().toString(),
									infoToken.getValue(FormFields.SCHOOLNAME)
											.toString());
							infoToken
									.putValue("displayMessage",
											"Course ID already exists. Please choose a new ID.");
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						}
						infoToken.putValue("classContainer", course);
						break;
					case FormFields.EDCLASSPAGE: // save class
					// TODO The following needs to getCourseContainer(id,
					// dbName);
						ClassContainer classcont = ClassContainer
								.getClassContainer(
										input
												.getParameter(SchoolDBSQL.CLASSASSIGNEDID),
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString());
						// Parse the information from the form and populate the
						// container
						FormParser.updateClass(input, classcont, infoToken
								.getValue(FormFields.SCHOOLNAME).toString());
						saveClassInfo(classcont, infoToken);
						if (classcont.getClassAssignedID().toString().equals(
								"-1")
								|| SchoolDBSQL.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString()).isUniqueClassID(
										classcont.getClassSchoolID())) {
							saveClassInfo(classcont, infoToken);
							infoToken.putValue("displayMessage",
									"Changes saved");
							loadEditorMainParameters(infoToken, editorPage);
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						} else {
							// TODO load the class editor instead of eview
							classcont.getClassSchoolID().setValue(
									"<enter new id>");
							loadEditClassInfo(infoToken, classcont
									.getClassAssignedID().toString(), infoToken
									.getValue(FormFields.SCHOOLNAME).toString());
							infoToken
									.putValue("displayMessage",
											"Class ID already exists. Please choose a new ID.");
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						}
						infoToken.putValue("classContainer", classcont);
						break;
					case FormFields.EDTERMPAGE: // save term
						TermContainer termcont = TermContainer
								.getTermContainer(
										input
												.getParameter(SchoolDBSQL.TERMASSIGNEDID),
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString());
						// Parse the information from the form and populate the
						// container
						FormParser.updateTerm(input, termcont, infoToken
								.getValue(FormFields.SCHOOLNAME).toString());
						saveTermInfo(termcont, infoToken);
						infoToken.putValue("displayMessage", "Changes saved");
						loadEditorMainParameters(infoToken, editorPage);
						disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						infoToken.putValue("termContainer", termcont);
						break;
					default: // save parent
					// TODO The following needs to getCourseContainer(id,
					// dbName);
						UserContainer parent = PairedUserContainer
								.getPairedContainer(
										input
												.getParameter(SchoolDBSQL.USRASSIGNEDID),
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString());
						// Parse the information from the form and populate the
						// container
						FormParser.updateUser(input, parent);
						saveParentInfo(input, parent, infoToken);
						if (parent.getAssignedID().toString().equals("-1")
								|| SchoolDBSQL.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString()).isUniqueUserID(
										parent.getSchoolID(), parent.getType())) {
							saveParentInfo(input, parent, infoToken);
							infoToken.putValue("displayMessage",
									"Changes saved");
							loadEditorMainParameters(infoToken, editorPage);
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						} else {
							// TODO load the parent editor instead of eview
							parent.getSchoolID().setValue("<enter new id>");
							loadEditParentInfo(infoToken, parent
									.getAssignedID().toString(), infoToken
									.getValue(FormFields.SCHOOLNAME).toString());
							infoToken
									.putValue("displayMessage",
											"Parent ID already exists. Please choose a new ID.");
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						}
						infoToken.putValue("parentContainer", parent);
						break;
					}

				}
				// If the user is trying to delete something, figure out the
				// type, get the assigned ID,
				// and move it and any dependent items into the deleted tables.
				else if (FormFields.DELETEACTION.equals(linkClicked)) {

					SchoolLogger.logger.log(Level.INFO,
							"Deleteaction -- editorPage: " + editorPage);

					switch (editorPage) {
					case FormFields.EDSTUDENTPAGE: // delete student
						SchoolDBSQL
								.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString())
								.moveUserToDeleted(
										UserContainer
												.getUserContainer(
														input
																.getParameter(SchoolDBSQL.USRASSIGNEDID),
														infoToken
																.getValue(
																		FormFields.SCHOOLNAME)
																.toString()));
						infoToken.putValue("displayMessage", "Student deleted");
						break;
					case FormFields.EDTEACHERPAGE: // delete teacher
						SchoolDBSQL
								.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString())
								.moveUserToDeleted(
										UserContainer
												.getUserContainer(
														input
																.getParameter(SchoolDBSQL.USRASSIGNEDID),
														infoToken
																.getValue(
																		FormFields.SCHOOLNAME)
																.toString()));
						infoToken.putValue("displayMessage", "Teacher deleted");
						break;
					case FormFields.EDCOURSEPAGE: // delete course
						SchoolDBSQL
								.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString())
								.moveCourseToDeleted(
										CourseContainer
												.getCourseContainer(
														input
																.getParameter(SchoolDBSQL.COURSEASSIGNEDID),
														infoToken
																.getValue(
																		FormFields.SCHOOLNAME)
																.toString()));
						infoToken.putValue("displayMessage", "Course deleted");
						break;
					case FormFields.EDCLASSPAGE: // delete class
						SchoolDBSQL
								.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString())
								.moveClassToDeleted(
										ClassContainer
												.getClassContainer(
														input
																.getParameter(SchoolDBSQL.CLASSASSIGNEDID),
														infoToken
																.getValue(
																		FormFields.SCHOOLNAME)
																.toString()));
						infoToken.putValue("displayMessage", "Class deleted");
						break;
					case FormFields.EDTERMPAGE: // delete term
						SchoolDBSQL
								.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString())
								.moveTermToDeleted(
										TermContainer
												.getTermContainer(
														input
																.getParameter(SchoolDBSQL.TERMASSIGNEDID),
														infoToken
																.getValue(
																		FormFields.SCHOOLNAME)
																.toString()));
						infoToken.putValue("displayMessage", "Class deleted");
						break;
					default: // delete parent
						SchoolDBSQL
								.getSchoolDBSQL(
										infoToken.getValue(
												FormFields.SCHOOLNAME)
												.toString())
								.moveUserToDeleted(
										UserContainer
												.getUserContainer(
														input
																.getParameter(SchoolDBSQL.USRASSIGNEDID),
														infoToken
																.getValue(
																		FormFields.SCHOOLNAME)
																.toString()));
						infoToken.putValue("displayMessage", "Parent deleted");
						break;
					}
					loadEditorMainParameters(infoToken, editorPage);
					disp = sc.getRequestDispatcher("/jsp/eview.jsp");
				}
				// If the user wants to change his or her password, send
				// the password change form
				// Note - the editor has a password form different from everyone
				// else because
				// of architecture differences. It would be nice to have a
				// similar architecture
				// in the rest of it.
				else if (FormFields.CHANGEPASSWORD.equals(linkClicked)) {

					infoToken.putValue(FormFields.EDITORPAGE, "" + editorPage);

					disp = sc
							.getRequestDispatcher("/jsp/EditorPasswordForm.jsp");
				}
				// If the user wants to save his or her password change, get the
				// input, validate
				// it, and save the change or send a 'bad password'-type
				// response
				else if ("Change Password".equals(linkClicked)) {
					infoToken.putValue(FormFields.EDITORPAGE, "" + editorPage);
					SchoolLogger.logger.log(Level.INFO,
							"current == Change Password");
					// if current password is valid, then
					UserContainer user = (UserContainer) infoToken
							.getValue("adminContainer");
					String oldPIParam = input.getParameter("CURRENTPASSWORD");
					PasswordItem oldPI = new PasswordItem(
							SchoolDBSQL.USRPASSWORD, oldPIParam, true);
					PasswordItem newPI = new PasswordItem(
							SchoolDBSQL.USRPASSWORD, (String) null, true);
					FormParser.getNewPassword(input, newPI);

					if (SecurityAuthorizer.isValidLogin(user.getAssignedID()
							.toString(), oldPIParam, infoToken.getValue(
							FormFields.SCHOOLNAME).toString())) {
						if (newPI.getObject() == null) {
							infoToken
									.putValue(
											"displayMessage",
											"The first new password you entered did not match the second. Your password has not been changed.");
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						} else {
							SchoolDBSQL.getSchoolDBSQL(
									infoToken.getValue(FormFields.SCHOOLNAME)
											.toString()).changeUserPassword(
									user.getAssignedID(), oldPI, newPI);
							infoToken.putValue("displayMessage",
									"Password changed");
							disp = sc.getRequestDispatcher("/jsp/eview.jsp");
						}
					} else {
						infoToken.putValue("displayMessage",
								"Password incorrect");
						disp = sc.getRequestDispatcher("/jsp/eview.jsp");
					}
				}
				// If the user wants to edit something
				// else if (FormFields.EDITACTION.equals(linkClicked)) {
				//
				// infoToken.putValue(FormFields.EDITSTATUS, FormFields.EDIT);
				//
				// loadEditorMainParameters(infoToken, editorPage);
				//
				// disp = sc.getRequestDispatcher("/EditorMain.jsp");
				//
				// }
				else if ("Cancel".equalsIgnoreCase(linkClicked)) {
					disp = sc.getRequestDispatcher("/jsp/eview.jsp");
				}
				// Otherwise, load the whole editor with the default (parent)
				// page
				// loaded
				else {

					loadEditorMainParameters(infoToken, gotoPage);

					disp = sc.getRequestDispatcher("/jsp/EditorMain.jsp");

				}
			}

			// Otherwise, load the whole editor with the default (parent) page
			// loaded
			else {

				SchoolLogger.logger.log(Level.INFO, "last else -- gotoPage: "
						+ gotoPage);
				loadEditorMainParameters(infoToken, gotoPage);

				disp = sc.getRequestDispatcher("/jsp/EditorMain.jsp");
			}
		}

		// Log who is logged in
		if (infoToken != null) {
			SecurityToken st = (SecurityToken) input
					.getAttribute(FormFields.SESSION);
			UserContainer adminContainer = (UserContainer) st
					.getValue("adminContainer");
			SchoolLogger.logger.log(Level.INFO, "adminContainer: "
					+ adminContainer);
			SchoolLogger.logger.log(Level.INFO, "fname: "
					+ adminContainer.getFirstName().toString());
			SchoolLogger.logger.log(Level.INFO, "lname: "
					+ adminContainer.getLastName().toString());
		}

		// Display the page
		response.setContentType("text/html; charset=ISO-8859-2");
		disp.include(input, response);
	}

	/**
	 * Saves a parent and his or her children
	 * 
	 * @param input
	 *            Input from the user form containing child data for the parent.
	 * @param parent
	 *            The parent container to save. This container is already
	 *            updated with form data.
	 */
	private void saveParentInfo(HttpServletRequest input, UserContainer parent,
			SecurityToken infoToken) {
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.deleteParentRelation(
						new StringItem(SchoolDBSQL.PARENTUSRASSIGNEDID, parent
								.getAssignedID().toString(), false));
		String children[] = FormParser.parseList(input
				.getParameter("ASSIGNEDCHILDREN"));
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString()).save(
				parent, parent.getPassword());
		for (int i = 0; i < children.length; i++) {
			SchoolDBSQL.getSchoolDBSQL(
					infoToken.getValue(FormFields.SCHOOLNAME).toString())
					.saveRelationship(parent.getAssignedID().toString(),
							children[i]);
		}
	}

	/**
	 * Saves a class.
	 * 
	 * @param classcont
	 *            The class container to be saved.
	 */
	private void saveClassInfo(ClassContainer classcont, SecurityToken infoToken) {
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString()).save(
				classcont);
	}

	/**
	 * Saves a term.
	 * 
	 * @param termcont
	 *            The term container to be saved.
	 */
	private void saveTermInfo(TermContainer termcont, SecurityToken infoToken) {
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString()).save(
				termcont);
	}

	/**
	 * Saves a course
	 * 
	 * @param course
	 *            The course container to be saved
	 */
	private void saveCourseInfo(CourseContainer course, SecurityToken infoToken) {
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString()).save(
				course);
	}

	/**
	 * Saves a teacher
	 * 
	 * @param input
	 *            Input from the user form containing class data for the
	 *            teacher.
	 * @param teachercont
	 *            The teacher container to save. This container is already
	 *            updated with form data.
	 */
	private void saveTeacherInfo(HttpServletRequest input,
			UserContainer teachercont, SecurityToken infoToken) {
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString()).save(
				teachercont, teachercont.getPassword());
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.saveTeacherClass(
						teachercont.getAssignedID(),
						FormParser.parseClassList(input
								.getParameter("ASSIGNEDCLASSES")));
	}

	/**
	 * Saves a student
	 * 
	 * @param input
	 *            Input from the user form containing parent and class data for
	 *            the student.
	 * @param studcont
	 *            The student container to save. This container is already
	 *            updated with form data.
	 */
	private void saveStudentInfo(HttpServletRequest input,
			UserContainer studcont, SecurityToken infoToken) {
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString()).save(
				studcont, studcont.getPassword());
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.deleteStudentRelation(
						new StringItem(SchoolDBSQL.STUDENTUSRASSIGNEDID,
								studcont.getAssignedID().toString(), false));
		String parents[] = FormParser.parseList(input
				.getParameter("ASSIGNEDPARENTS"));
		for (int i = 0; i < parents.length; i++) {
			SchoolDBSQL.getSchoolDBSQL(
					infoToken.getValue(FormFields.SCHOOLNAME).toString())
					.saveRelationship(parents[i],
							studcont.getAssignedID().toString());
		}
		SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.saveStudentClass(
						studcont.getAssignedID(),
						FormParser.parseClassList(input
								.getParameter("ASSIGNEDCLASSES")));
	}

	/**
	 * Loads a parent, children, and available children, and inserts the parent
	 * container into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the parent to load.
	 */
	private void loadEditParentInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.EDIT);
		infoToken.putValue("assignedChildList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadParentsChildren(id));
		// infoToken.putValue(
		// "availableChildList",
		// SchoolDBSQL.getSchoolDBSQL(
		// infoToken.getValue(FormFields.SCHOOLNAME).toString()).loadAvailableClassList());
		infoToken.putValue("availableChildList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailadbleChildren());
		infoToken.putValue("parentContainer", PairedUserContainer
				.getPairedContainer(id, dbName));
	}

	/**
	 * Loads a class and inserts the class container into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the class to load.
	 */
	private void loadEditClassInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.EDIT);
		infoToken.putValue("classContainer", ClassContainer.getClassContainer(
				id, dbName));
		infoToken.putValue("periodList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadPeriodList());
		infoToken.putValue("courseList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadEditorCourseList());
	}

	/**
	 * Loads a class and inserts the class container into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the class to load.
	 */
	private void loadEditTermInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.EDIT);
		infoToken.putValue("termContainer", TermContainer.getTermContainer(id,
				dbName));
	}

	/**
	 * Loads a course and inserts the course container into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the course to load.
	 */
	private void loadEditCourseInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.EDIT);
		infoToken.putValue("courseContainer", CourseContainer
				.getCourseContainer(id, dbName));
	}

	/**
	 * Loads a teacher, classes, and available classes, and inserts the teacher
	 * container into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the teacher to load.
	 */
	private void loadEditTeacherInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.EDIT);
		infoToken.putValue("teacherContainer", UserContainer.getUserContainer(
				id, dbName));
		infoToken.putValue("availableClassList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailableClassList());
		infoToken.putValue("assignedClassList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadTeacherAssignedClassList(
						new StringItem(SchoolDBSQL.USRASSIGNEDID, id, true)));
	}

	/**
	 * Loads a student,classes, parents, available classes, and available
	 * parents, and inserts the student container into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the student to load.
	 */
	private void loadEditStudentInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.EDIT);
		infoToken.putValue("studentContainer", PairedUserContainer
				.getPairedContainer(id, dbName));
		infoToken.putValue("availableClassList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailableClassList());
		infoToken.putValue("assignedClassList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadStudentAssignedClassList(
						new StringItem(SchoolDBSQL.USRASSIGNEDID, id, true)));
		infoToken.putValue("assignedParentList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadChildrensParents(id));
		infoToken.putValue("availableParentList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailableParents());
	}

	/**
	 * Loads available children and an empty parent into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 */
	private void loadNewParentInfo(SecurityToken infoToken, String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.NEW);
		// TODO The following needs to getCourseContainer(id, dbName);
		infoToken.putValue("parentContainer", PairedUserContainer
				.getPairedContainer("-1", dbName));
		infoToken.removeValue("assignedChildList");
		// infoToken.putValue(
		// "availableChildList",
		// SchoolDBSQL.getSchoolDBSQL(
		// infoToken.getValue(FormFields.SCHOOLNAME).toString()).loadAvailableClassList());
		infoToken.putValue("availableChildList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailadbleChildren());
	}

	/**
	 * Loads available courses into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 */
	private void loadNewCourseInfo(SecurityToken infoToken) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.NEW);
		infoToken.putValue("periodList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadPeriodList());
		infoToken.putValue("courseList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadEditorCourseList());
	}

	/**
	 * Loads available classes and an empty teacher into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 */
	private void loadNewTeacherInfo(SecurityToken infoToken, String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.NEW);
		infoToken.putValue("teacherContainer", UserContainer.getUserContainer(
				"-1", dbName));
		infoToken.removeValue("assignedClassList");
		infoToken.putValue("availableClassList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailableClassList());
	}

	/**
	 * Loads available classes, available parents, and an empty student into the
	 * token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 */
	private void loadNewStudentInfo(SecurityToken infoToken, String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.NEW);
		// TODO The following needs to getCourseContainer(id, dbName);
		infoToken.putValue("studentContainer", PairedUserContainer
				.getPairedContainer("-1", dbName));
		infoToken.removeValue("assignedClassList");
		infoToken.putValue("availableClassList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailableClassList());
		infoToken.removeValue("assignedParentList");
		infoToken.putValue("availableParentList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailableParents());
	}

	/**
	 * Loads a parent, along with assigned children, into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the parent to load.
	 */
	private void loadViewParentInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.VIEW);
		infoToken.putValue("parentContainer", PairedUserContainer
				.getPairedContainer(id, dbName));
		infoToken.putValue("assignedChildList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadParentsChildren(id));
		// TODO This can probably be removed.
		// infoToken.putValue(
		// "availableChildList",
		// SchoolDBSQL.getSchoolDBSQL(
		// infoToken.getValue(FormFields.SCHOOLNAME).toString()).loadAvailableClassList());
		infoToken.putValue("availableChildList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailadbleChildren());
	}

	/**
	 * Loads a class, along with the assigned course, students, and teachers,
	 * into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the class to load.
	 */
	private void loadViewClassInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.VIEW);
		Item classID = new StringItem(SchoolDBSQL.CLASSASSIGNEDID, id, false);
		infoToken.putValue("classContainer", ClassContainer.getClassContainer(
				id, dbName));
		infoToken.putValue("courseList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadEditorCourseList());
		infoToken.putValue("classTeacher", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadTeacherFromClassID(classID));
		infoToken.putValue("studentList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadClassEnrollment(classID));
	}

	/**
	 * Loads a class, along with the assigned course, students, and teachers,
	 * into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the class to load.
	 */
	private void loadViewTermInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.VIEW);
		infoToken.putValue("termContainer", TermContainer.getTermContainer(id,
				dbName));
	}

	/**
	 * Loads a course, along with assigned classes and teachers, into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the course to load.
	 */
	private void loadViewCourseInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.VIEW);
		Item[][] assignedClassList;
		Item[][][] assignedTeacherList;
		infoToken.putValue("courseContainer", CourseContainer
				.getCourseContainer(id, dbName));
		assignedClassList = SchoolDBSQL
				.getSchoolDBSQL(
						infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadCourseClassList(
						new StringItem(SchoolDBSQL.COURSEASSIGNEDID, id, false));
		assignedTeacherList = new Item[assignedClassList.length][][];
		for (int i = 0; i < assignedClassList.length; i++) {
			assignedTeacherList[i] = SchoolDBSQL.getSchoolDBSQL(
					infoToken.getValue(FormFields.SCHOOLNAME).toString())
					.loadTeacherFromClassID(assignedClassList[i][0]);
		}
		infoToken.putValue("assignedClassList", assignedClassList);
		infoToken.putValue("assignedTeacherList", assignedTeacherList);
	}

	/**
	 * Loads a teacher, along with classes, into the token
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the teacher to load.
	 */
	private void loadViewTeacherInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.VIEW);
		Item[][] assignedClassList;
		infoToken.putValue("teacherContainer", UserContainer.getUserContainer(
				id, dbName));
		assignedClassList = SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadTeacherAssignedClassList(
						new StringItem(SchoolDBSQL.USRASSIGNEDID, id, true));
		infoToken.putValue("assignedClassList", assignedClassList);
		int enrollmentCount[] = new int[assignedClassList.length];
		for (int i = 0; i < assignedClassList.length; i++) {
			enrollmentCount[i] = SchoolDBSQL.getSchoolDBSQL(
					infoToken.getValue(FormFields.SCHOOLNAME).toString())
					.getClassSize(assignedClassList[i][0]);
		}
		infoToken.putValue("enrollmentCount", enrollmentCount);
	}

	/**
	 * Loads a student, along with classes, teachers, and parents, into the
	 * token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param id
	 *            The assigned ID of the student to load.
	 */
	private void loadViewStudentInfo(SecurityToken infoToken, String id,
			String dbName) {
		infoToken.putValue(FormFields.EDITSTATUS, FormFields.VIEW);
		Item[][] assignedClassList;
		Item[][][] assignedTeacherList;
		infoToken.putValue("studentContainer", PairedUserContainer
				.getPairedContainer(id, dbName));
		assignedClassList = SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadStudentAssignedClassList(
						new StringItem(SchoolDBSQL.USRASSIGNEDID, id, true));
		assignedTeacherList = new Item[assignedClassList.length][][];
		for (int i = 0; i < assignedClassList.length; i++) {
			assignedTeacherList[i] = SchoolDBSQL.getSchoolDBSQL(
					infoToken.getValue(FormFields.SCHOOLNAME).toString())
					.loadTeacherFromClassID(assignedClassList[i][0]);
		}
		infoToken.putValue("assignedClassList", assignedClassList);
		infoToken.putValue("assignedTeacherList", assignedTeacherList);
		infoToken.putValue("assignedParentList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadChildrensParents(id));
		infoToken.putValue("availableParentList", SchoolDBSQL.getSchoolDBSQL(
				infoToken.getValue(FormFields.SCHOOLNAME).toString())
				.loadAvailableParents());
	}

	/**
	 * Loads a list of the appropriate type of objects (teacher, class, etc.)
	 * into the token.
	 * 
	 * @param infoToken
	 *            The token where the information is to be stored.
	 * @param gotoPage
	 *            The page whose information should be loaded.
	 */
	private void loadEditorMainParameters(SecurityToken infoToken, int gotoPage) {

		switch (gotoPage) {
		case FormFields.EDSTUDENTPAGE: // load student list
			infoToken.putValue("displayContentList", SchoolDBSQL
					.getSchoolDBSQL(
							infoToken.getValue(FormFields.SCHOOLNAME)
									.toString()).loadEditorStudentList());
			infoToken.putValue("displayTitleList", new String[] { "School ID",
					"First Name", "Last Name" });
			infoToken
					.putValue("displayLengthList", new int[] { 115, 115, 115 });
			infoToken.putValue(FormFields.EDITORPAGE, ""
					+ FormFields.EDSTUDENTPAGE);
			break;
		case FormFields.EDTEACHERPAGE: // load teacher list
			infoToken.putValue("displayContentList", SchoolDBSQL
					.getSchoolDBSQL(
							infoToken.getValue(FormFields.SCHOOLNAME)
									.toString()).loadEditorTeacherList());
			infoToken.putValue("displayTitleList", new String[] { "School ID",
					"First Name", "Last Name" });
			infoToken
					.putValue("displayLengthList", new int[] { 115, 115, 115 });
			infoToken.putValue(FormFields.EDITORPAGE, ""
					+ FormFields.EDTEACHERPAGE);
			break;
		case FormFields.EDCOURSEPAGE: // load course list
			infoToken.putValue("displayContentList", SchoolDBSQL
					.getSchoolDBSQL(
							infoToken.getValue(FormFields.SCHOOLNAME)
									.toString()).loadEditorCourseList());
			infoToken.putValue("displayTitleList", new String[] { "Course ID",
					"Name" });
			infoToken.putValue("displayLengthList", new int[] { 115, 280 });
			infoToken.putValue(FormFields.EDITORPAGE, ""
					+ FormFields.EDCOURSEPAGE);
			break;
		case FormFields.EDCLASSPAGE: // load class list
			infoToken.putValue("displayContentList", SchoolDBSQL
					.getSchoolDBSQL(
							infoToken.getValue(FormFields.SCHOOLNAME)
									.toString()).loadAvailableClassList());
			infoToken.putValue("displayTitleList", new String[] { "Class ID",
					"Hour" });
			infoToken.putValue("displayLengthList", new int[] { 115, 115 });
			infoToken.putValue(FormFields.EDITORPAGE, ""
					+ FormFields.EDCLASSPAGE);
			break;
		case FormFields.EDTERMPAGE: // load term list
			infoToken.putValue("displayContentList", SchoolDBSQL
					.getSchoolDBSQL(
							infoToken.getValue(FormFields.SCHOOLNAME)
									.toString()).loadAvailableTermList());
			infoToken.putValue("displayTitleList", new String[] { "Term Name",
					"Start Date", "End Date" });
			infoToken.putValue("displayLengthList", new int[] { 115, 75, 75 });
			infoToken.putValue(FormFields.EDITORPAGE, ""
					+ FormFields.EDTERMPAGE);
			break;
		default: // load parent list
			infoToken.putValue("displayContentList", SchoolDBSQL
					.getSchoolDBSQL(
							infoToken.getValue(FormFields.SCHOOLNAME)
									.toString()).loadEditorParentList());
			infoToken.putValue("displayTitleList", new String[] { "School ID",
					"First Name", "Last Name" });
			infoToken
					.putValue("displayLengthList", new int[] { 115, 115, 115 });
			infoToken.putValue(FormFields.EDITORPAGE, ""
					+ FormFields.EDPARENTPAGE);
			break;
		}
	}

	/**
	 * Forwards all calls to doPost
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	public void doGet(HttpServletRequest input, HttpServletResponse response)
			throws ServletException, IOException {

		SchoolLogger.logger
				.log(Level.INFO,
						"//////////////////////////////////////////////////////////////");
		// SchoolLogger.logger.log(Level.INFO, "ClassEditorCMD.doGet -
		// input.getParameter(\"id\"): " + input.getParameter("id"));

		doPost(input, response);

	}
}
